from selenium import webdriver
from config.setting import browserpath, time_wite, host_port
'''
2021-6-26 9:46
单例模式
'''
class DriverFactory1():
    driver = None

    @classmethod
    def getDriver(cls, browser = 'Chrome'):
        if cls.driver == None:
            if browser == 'Chrome':
                cls.driver = webdriver.Chrome(browserpath['Chrome'])
                cls.driver.maximize_window()
                cls.driver.implicitly_wait(time_wite)
                DriverFactory1.login()
            elif browser == 'Edge':
                cls.driver = webdriver.Edge(browserpath['Edge'])
                cls.driver.maximize_window()
                cls.driver.implicitly_wait(time_wite)
                DriverFactory1.login()
            elif browser == 'Firefox':
                cls.driver = webdriver.Firefox(browserpath['Firefox'])
                cls.driver.maximize_window()
                cls.driver.implicitly_wait(time_wite)
                # DriverFactory.login()
            else:
                print(f'不支持{browser}浏览器！')

        return cls.driver

    @classmethod
    def login(cls):
        cls.driver.get(f'http://{host_port}/SharedParkingPlace')
        cls.driver.find_element_by_id('uname').send_keys('抢租客0')
        cls.driver.find_element_by_id('upass').send_keys('123')
        cls.driver.find_element_by_id('imgcode').send_keys('0000')
        cls.driver.find_element_by_id('button').click()



